home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / cm / integer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-31  |  2.1 KB  |  57 lines

  1. // integer.h
  2. //
  3. // Example class definition.  This simple integer class is derived
  4. // from the abstract class "CmObject".  All of the virtual functions
  5. // in the base class are redefined and some simple lexical operators
  6. // are also defined making this class usable with both the object
  7. // and template based containers.
  8. //
  9. #ifndef INTEGER_H
  10. #define INTEGER_H
  11.  
  12. #include <cm/include/cmobject.h>
  13.  
  14. class Integer : public CmObject {          // Integer class definition.
  15. public:
  16.   Integer(int v = 0) : _value(v) {}        // Default integer constructor.
  17.  
  18.   operator int() const;                    // Type conversion operator.
  19.  
  20.   void value(int);                         // Set new integer value.
  21.   int  value() const;                      // Return integer value.
  22.  
  23.   CMOBJECT_DEFINE(Integer, CmObject)       // Define base. (A MUST!!)
  24.  
  25.   Bool     isEqual (CmObject*) const;      // Compare objects.
  26.   int      compare (CmObject*) const;      // Compare objects.
  27.   unsigned hash    (unsigned)  const;      // Hash function.
  28.   void     printOn (ostream&)  const;      // Print to stream.
  29.   void     readFrom(istream&);             // Read from stream.
  30.   Bool     write   (CmReserveFile&) const; // Write to reserve file.
  31.   Bool     read    (CmReserveFile&);       // Read from reserve file.
  32.  
  33.   Bool operator< (const Integer&) const;   // Is this <  input?
  34.   Bool operator<=(const Integer&) const;   // Is this <= input?
  35.   Bool operator> (const Integer&) const;   // Is this >  input?
  36.   Bool operator>=(const Integer&) const;   // Is this >= input?
  37.   Bool operator==(const Integer&) const;   // Is this == input?
  38.   Bool operator!=(const Integer&) const;   // Is this != input?
  39.  
  40. private:
  41.   int _value;                              // Integer value.
  42. };
  43.  
  44. // "int" type conversion operator returns the integer value.
  45. inline Integer::operator int() const
  46. { return _value; }
  47.  
  48. // "value" sets a new integer value.
  49. inline void Integer::value(int v)
  50. { _value = v; }
  51.  
  52. // "value" returns the integer value.
  53. inline int Integer::value() const
  54. { return _value; }
  55.  
  56. #endif
  57.